package com.qianxun.entrace.service;

import com.qianxun.framework.web.util.WebUtil;
import com.qianxun.plugins.log.LogInfo;
import com.qianxun.plugins.log.Logger;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户方法日志
 * @author: huwei
 * @date: 2019/10/17 15:12
 * @version: 1.0.0
 */
@Slf4j
public class UserAccessLoggerService extends Logger {

    private String accessUrl;

    @Override
    public void beforeLog(LogInfo logInfo) {
        HttpServletRequest request = (HttpServletRequest) logInfo.getParameterMap().get("request");
        accessUrl = WebUtil.completeRequestUrl(request);
        StringBuffer stringBuffer = new StringBuffer("\r\n");
        stringBuffer.append("用户访问开始：").append(accessUrl);
        log.info(stringBuffer.toString());
    }

    @Override
    public void errorLog(LogInfo logInfo) {
        StringBuffer stringBuffer = new StringBuffer("\r\n");
        stringBuffer.append("用户访问异常：").append(accessUrl);
        log.info(stringBuffer.toString());
    }

    @Override
    public void afterLog(LogInfo logInfo) {
        StringBuffer stringBuffer = new StringBuffer("\r\n");
        stringBuffer.append("用户访问结束：").append(accessUrl);
        log.info(stringBuffer.toString());
    }
}
